﻿using Jayden.Dll.Web.HtmlControls;

namespace Jayden.Dll.Web.Controls.Admin
{
	public class CreateRoleForm : Form
	{
		private Input m_Roles;
		private Button m_CreateRoles;

		public override void Load(System.Xml.XmlNode node, HtmlControlLoader loader)
		{
			base.Load(node, loader);
			if (Id == null)
				Id = "createRoleForm";
			m_Roles = GetFormElement<Input>("roles");
			m_CreateRoles = GetFormElement<Button>("createRoles", "command");
		}

		public override void ProcessHtmlRequest(HttpHandlerContext context)
		{
			RoleProviderDiv.RoleCommandHandler roleHandler = context.HandlerManager.GetHandler<RoleProviderDiv.RoleCommandHandler>();
			roleHandler.RolesCreated += new RoleProviderDiv.OnRolesCreated(RolesCreated);
			base.ProcessHtmlRequest(context);
		}

		public override void ProcessJsonRequest(HttpHandlerContext context)
		{
			RoleProviderDiv.RoleCommandHandler roleHandler = context.HandlerManager.GetHandler<RoleProviderDiv.RoleCommandHandler>();
			roleHandler.RolesCreated += new RoleProviderDiv.OnRolesCreated(RolesCreated);
			base.ProcessJsonRequest(context);
		}

		public override void ProcessJsRequest(HttpHandlerContext context)
		{
			base.ProcessJsRequest(context);
			string id = Id;
			context.Js[id].AppendAjaxSubmit(this, m_CreateRoles);
		}

		void RolesCreated(HttpHandlerContext context, string[] roles)
		{
			//throw new NotImplementedException();
		}
	}
}
